import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p001 from './p001';
import p003 from './p003';
import { strict } from 'assert';
import format from '@dfeidao/atom-web/dt/format';
import p002 from './p002';

export default async function a002(fd: IFeidaoAiBrowserComponent,xname:string,laiyuan:string,jctt:string) {
		// todo	q
		const res = await nodejs<{ dt1: Array<{ work_bill_no: string, job_content: string, cust_name: string, project_name: string, work_order_status: string, responsible: string, source_type: string, revisit_days: string, cust_sat: string }>; c: number }>('order-satisfaction/zj-000002/s003', {
			filter: {
				Pn: 1,
				project_no: xname,
				job_content: jctt,
				value: laiyuan
	
			}
		});
		for (let i = 0; i < res.dt1.length; i++) {
			if (res.dt1[i].source_type === "1") {
				res.dt1[i].source_type = "总服务台";
			} else if (res.dt1[i].source_type === "2") {
				res.dt1[i].source_type = "服务台";
	
			} else if (res.dt1[i].source_type === "3") {
				res.dt1[i].source_type = "客户报障";
	
			} else {
				res.dt1[i].source_type = "内部报障";
			}
	
	
		}
		const ret = Array();
		for (let i = 0; i < res.dt1.length; i++) {
			ret[i] = res.dt1[i].work_bill_no;
		}
		const rer = await nodejs<{ dt1: Array<{ work_bill_no: string, revisit_days: number, cust_sat: string }>; dt2: Array<{ cust_sat: string }> }>("order-satisfaction/zj-000002/s004", { filter: { work_bill_no: ret } });
		const p = rer.dt1.map((n) => {
			return { ...n, revisit_days: format(n.revisit_days, 2) };
		});
		const q = Array();
	for (let index = 0; index < res.dt1.length; index++) {
		for (let i = 0; i < rer.dt1.length; i++) {
			if (res.dt1[index].work_bill_no === rer.dt1[i].work_bill_no) {
				q[index] = {
					work_bill_no: res.dt1[index].work_bill_no, job_content: res.dt1[index].job_content, source_type: res.dt1[index].source_type,
					cust_name: res.dt1[index].cust_name, project_name: res.dt1[index].project_name, work_order_status: res.dt1[index].work_order_status,
					responsible: res.dt1[index].responsible, revisit_days: p[index].revisit_days,cust_sat: p[i].cust_sat
				};

			}
		}
	}
		for (let i = 0; i < q.length; i++) {
			if (q[i].cust_sat == "1") {
				q[i].cust_sat = "非常满意";
			} else if (q[i].cust_sat == "2") {
				q[i].cust_sat = "满意";
	
			} else if (q[i].cust_sat == "3") {
				q[i].cust_sat = "一般";
	
			} else if (q[i].cust_sat == "4") {
				q[i].cust_sat = "不满意";
			} else {
				q[i].cust_sat = "未回访";
	
			}
		}
		const dtNO = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p001"]');
		const dtH = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p002"]');
		if (q.length > 0) {
			render(fd, q, p001, 'p001', 'inner');
			dtNO.style.display = 'block';
			dtH.style.display = 'none';
		} else {
			render(fd, '', p002, 'p002', 'inner');
			dtNO.style.display = 'none';
			dtH.style.display = 'block';
		}
		if (q.length > 20) {
			render(fd, q.length, p003, 'p003', 'inner');
		}
		
	
}
